Skip to content

feat(id): TenantOpsDO provisioning state machine (E2 of #9083) - #14392

Merged
developing-today-fleet[bot] merged 2 commits into
mainfrom
felix/12797-tenantops-provisioning
Nov 24, 2026
Merged

developing-today-fleet[bot] merged 2 commits into
mainfrom
felix/12797-tenantops-provisioning

Conversation

@developing-today-fleet

@developing-today-fleet developing-today-fleet Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #12797 (E2 of #9083; Felix: done-check on merge is yours — acceptance mapping below).

What this is

TenantOpsDO — the §4 provisioning state machine of the hosted-tenancy design record (doc/2026-11-17T16-55-00Z_design_hosted-tenancy-architecture), implemented in pkgs/id/hosted-worker/src/tenant-ops.ts on the E1 baseline (PR #13042). One object per tenant, keyed by binding_id (§3), driving the tenant_db row:

requested → db_creating → db_ready → active, with suspended ⇄ active, export_only, two-phase deleting → deleted, and failed from requested (validation) and db_creating (permanent provider refusal).

How the §4 rules are kept

  • The row is the record; the object is the lock. Every route runs inside a per-object serialisation gate, including across the provider call — the exact window where a second sign-up would otherwise slip in.
  • Intent-first creation. The request id is a pure function of the tenant id (provisioningRequestId); the row records the intent before any provider call. Retries adopt the database the intent already made (checked before creating, and again after any create error — a lost response adopts, never duplicates).
  • Retry + compensation. Retryable provider failures retry in-call with the same request id (bounded), then leave the row db_creating — never failed on a transient fault — for the next drive. Permanent refusal fails the tenant with nothing left at the provider.
  • Actors. Each step checks the actor §4 names (owner = the bound binding itself, operator, platform, abuse/ceiling triggers) arriving on internal headers set by the tenancy Worker after authentication — the front door's trust posture. Owner of a different binding, unnamed roles, and missing actors all fail closed.
  • Two-phase deletion. Initiation (owner, from export_only only) revokes all credential metadata first and opens the cooling-off window (TENANT_DELETION_COOLING_OFF_MS, default 24h); completion drops the database and writes the tombstone. A stuck deleting tenant has no working credentials — the safe half-state.
  • Seams, stated in the module header. The Turso management API is an idempotent provider interface; unconfigured, provisioning/drops fail closed (503 provider_unavailable). The tenancy SQL handle is the object's storage with the tenancy migrations applied — the E6 adapter is where a Turso-over-HTTP handle plugs in. Credential issuance stays E4; this slice only revokes, as §4 step 10 requires. E2 needed no migration: the baseline row carries every field the machine writes.

Verification (remote only)

Run 45405972563 on head 71356ecd2 (the run shows cancelled only because I cancelled it during the known fleet-command Post Execute hang, after the execute step completed; full log read):

  • Executor image has no node/npm (fleet-command executor: ring/aws-lc-sys build-script binary fails to execute (os error 2) — native build-script dependency trees unbuildable dezren39/fleet#111 family; first dispatch 45400383397 died on npm: command not found), so the command put the runner toolcache's Node on PATH: node v24.22.3, npm 11.19.1, npm install (78 packages).
  • npm run typecheck (tsc --noEmit, strict): clean.
  • npm test (full package suite, 22 files): 171 tests, 171 pass, 0 fail. The 14 new tests in test/tenant-ops.test.ts, by name: the §4 lifecycle end to end with two-phase deletion; concurrent sign-ups create exactly one database (§11 item 2) — duplicate racing requests + provisions against a slow provider, createCalls == 1, plus a restarted second instance still creating nothing; crash-after-creation adoption; lost-response adoption; same-request-id retry; retryable exhaustion staying db_creating; permanent refusal → failed with no database left; no-binding validation → failed; activation gated on observed bootstrap; the full §4 actor matrix (every step tried by every unnamed actor, state unmoved); trigger scope (abuse suspends, ceiling forces export-only, neither does the other's step); cooling-off refusal with revocation already applied; wrong-state refusals and idempotent repeats; no-provider fail-closed.
  • The suite runs the machine against the real E1 migrations (applied from tenancy/migrations/, as tenancy-schema.test.ts does), never a schema copy.

Book live update (in-slice)

The slice adds src/tenant-ops.ts and the TENANT_OPS binding, moving id-book statements: pkgs/id/book/reference/hosted-worker.md gains the TENANT_OPS binding row, a TenantOpsDO routes section (routes, §4 actors, failure shapes), the unrouted-surfaces row, and the source line; pkgs/id/book/concepts/hosted.md's package enumeration gains tenant-ops.ts. design/hosted-editions.md was checked: its tenancy statements concern a running service, which this scaffold slice is not — nothing there moves. Package READMEs (hosted-worker/README.md, tenancy/README.md) updated for the same facts, including the correction that E2 landed with no new migration. Book not rebuilt in this pass (no SUMMARY/H1/link structure changed); the post-merge Pages check owns the render verification.

New dependencies: none. No secrets in code or logs — the platform Turso credential is referenced by name only and never leaves the Worker; tests use a fake provider.

{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-24T13:52:24Z",
    "session_id": null,
    "lane": null,
    "host": "htch-runtime",
    "worktree": "/home/hatch",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/hatch",
      "repo": "developing-today/code",
      "branch": "main",
      "sha": "c11f41086f57d626be7eb582763b721f8f557408"
    },
    "auth_subject": "felix",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

felix added 2 commits November 24, 2026 13:08
Implements design §4 on the E1 baseline: one TenantOpsDO per
tenant keyed by binding_id, driving the tenant_db row through
requested → db_creating → db_ready → active, with suspension,
export-only and two-phase deletion (revoke credentials, cooling-off
window, drop, tombstone).

Creation is intent-first: the deterministic request id is a pure
function of the tenant id, the row records the intent before the
provider call, and retries adopt the database the intent already
made — concurrent sign-ups create exactly one database (test
proves it against the real E1 schema). Every transition checks
the §4 actor (owner = the bound binding, operator, platform,
abuse/ceiling triggers) on internal headers and fails closed.

The Turso management API is a provider seam (idempotent create /
find / drop); no provider configured fails closed. Credential
issuance stays E4; this slice only revokes on deletion, as §4
step 10 requires.
Book live update (book-live-update rule): the slice adds
src/tenant-ops.ts and the TENANT_OPS binding, which moves
statements in the id book — reference/hosted-worker.md gains the
binding row, a TenantOpsDO routes section and the unrouted-surface
row; concepts/hosted.md's package enumeration gains tenant-ops.ts.
design/hosted-editions.md checked: its tenancy statements are
about a running service, which this scaffold slice is not, so
nothing there moves. Package READMEs updated for the same facts.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 12bd5a9e-e706-4937-81c5-7f76df55ea86

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@developing-today-fleet
developing-today-fleet Bot merged commit 9e955bb into main Nov 24, 2026
2 checks passed
@developing-today-fleet
developing-today-fleet Bot deleted the felix/12797-tenantops-provisioning branch November 24, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

impl(pm-stack): E2 — TenantOpsDO provisioning state machine (#9083)

0 participants